package com.comment.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.smartstruts.action.Action;
import org.smartstruts.action.ActionForm;

import com.comment.domain.Account;
import com.comment.form.LoginForm;
import com.comment.service.AccountService;
import com.comment.util.Constants;

/**
 * 登录验证类
 * 
 * @author Wangpeihu
 * 
 */
public class LoginAction extends Action {
	AccountService as = new AccountService();

	@Override
	public String execute(ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		LoginForm lf = (LoginForm) form;
		Account account = as
				.validateAccount(lf.getUsername(), lf.getPassword());
		if (account != null) {
			HttpSession session = request.getSession();
			session.setAttribute(Constants.ACCOUNT_KEY, account);
			System.out.println("返回了success----" + "帐户是：" + account.getName()
					+ "；密码是：" + account.getPassword());
			return "success";
		} else {
			System.out.println("返回了fail");
			return "fail";
		}
	}

}
